package ${package.Controller};

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器层
 * </p>
 *
 * @author ${author}
 * @Create_Date: ${date}
 * @Modified_By: ${author}
 * @Modified_Date: ${date}
 * @Why_and_What_is_modified: <br>
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName?lower_case}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen?lower_case}<#else>${table.entityPath?lower_case}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

	@Autowired
	${table.serviceName}  ${table.serviceName?lower_case};

	@GetMapping("/{id}")
	${entity} getByid(@PathVariable(value = "id") String id) {
		${entity} ${entity?lower_case} = ${table.serviceName?lower_case}.getById(id);
		return ${entity?lower_case};
	}

	@PostMapping
	${entity} add(${entity} ${entity?lower_case}) {
		${table.serviceName?lower_case}.save(${entity?lower_case});
		return ${entity?lower_case};
	}

	@DeleteMapping("/{id}")
	void delById(@PathVariable(value = "id") String id) {
		${table.serviceName?lower_case}.removeById(id);
	}

	@PatchMapping("/{id}")
	${entity} update(${entity} ${entity?lower_case}) {
		${table.serviceName?lower_case}.updateById(${entity?lower_case});
		return ${entity?lower_case};
	}

	@GetMapping("/list")
	Page<${entity}> list() {
		Page<${entity}> page = ${table.serviceName?lower_case}.page(new Page<>(0, 5));
		return page;
	}

<#if f.pclist??&&(f.pclist?size>0)>
	<#if f.pclist.querycolumn??&&(f.pclist.querycolumn?size>0)>
	@PostMapping("/list")
	Page<${entity}> pagepclist(@RequestParam int pageSize, @RequestParam int currentPage,
	<#list f.pclist.querycolumn as i>
    @RequestParam(required = false) String ${i} <#if i_has_next>,</#if> </#list> ) {
		Page<${entity}> page = new Page<${entity}>(currentPage, pageSize);
		QueryWrapper<${entity}> qw = new QueryWrapper<${entity}>();

	<#list f.pclist.querycolumn as i>
    if (StringUtils.isNotBlank(${i})) {
			qw.eq("${i}", ${i});
		}
    </#list>
		page = ${table.serviceName?lower_case}.page(page, qw);
		return page;
	}
	</#if>
</#if>




}
</#if>
